//
//  XKTradeMarketCell.m
//  XKJY
//
//  Created by xuyaguang on 2017/1/13.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "XKTradeMarketCell.h"

@interface XKTradeMarketCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *numberLabel;

@end

@implementation XKTradeMarketCell

#pragma mark - 自定义cell重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configArguments];
        [self createSubviews];
        
    }
    return self;
}

#pragma mark - 设置自身
- (void)configArguments {
    self.backgroundColor = WhiteColor;
}

#pragma mark - 创建控件
- (void)createSubviews {
    _titleLabel = [UILabel getLabWithText:@"--" textFont:Font_13 textColor:BlackColor textAlignment:NSTextAlignmentLeft];
    _priceLabel = [UILabel getLabWithText:@"--" textFont:Font_13 textColor:BlackColor textAlignment:NSTextAlignmentLeft];
    _numberLabel = [UILabel getLabWithText:@"--" textFont:Font_13 textColor:BlackColor textAlignment:NSTextAlignmentRight];
    
    [self.contentView addSubview:_titleLabel];
    [self.contentView addSubview:_priceLabel];
    [self.contentView addSubview:_numberLabel];
    
    [self addConstraints];
}
#pragma mark - 添加约束
- (void)addConstraints {
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(10*Scale_W);
        make.width.mas_equalTo(50*Scale_W);
        make.top.mas_equalTo(self.contentView).offset(3*Scale_H);
        make.bottom.mas_equalTo(self.contentView).offset(-3*Scale_H).priorityHigh();
    }];
    
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(10*Scale_W);
        make.centerY.mas_equalTo(self.titleLabel);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView).offset(-10*Scale_W);
        make.centerY.mas_equalTo(self.titleLabel);
    }];
    
    
}

- (void)setRecoderModel:(XKTradeRecoderModel *)recoderModel {
    _recoderModel = recoderModel;
    
    self.priceLabel.font  = [UIFont systemFontOfSize:13*Scale_W];
    self.titleLabel.font  = [UIFont systemFontOfSize:13*Scale_W];
    self.numberLabel.font = [UIFont systemFontOfSize:13*Scale_W];
    
    if ([recoderModel.type isEqualToString:@"sell"]) {
        self.titleLabel.text = [NSString stringWithFormat:@"卖(%@)",recoderModel.order];
        self.priceLabel.textColor = UIColorFromRGB(0x4DB54F);
    } else if ([recoderModel.type isEqualToString:@"buy"]) {
        self.titleLabel.text = [NSString stringWithFormat:@"买(%@)",recoderModel.order];
        self.priceLabel.textColor = UIColorFromRGB(0xFD5251);

    }
    
    NSString *numberText = [NSString changeNumberFormat:NSNumberFormatterDecimalStyle withNumber:[NSString calculateNumberOne:recoderModel.num calculateType:CalculateType_Subtract numberTwo:recoderModel.trade_num]];
    NSString *priceLabel = [NSString changeNumberFormat:recoderModel.price];
    self.priceLabel.text = priceLabel;
    self.numberLabel.text = numberText;
}

@end
